home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TestMoreOSUtils.c
-
- Contains: Simple test program for the MoreOSUtils library.
-
- Written by: Quinn
-
- Copyright: Copyright © 1999 by Apple Computer, Inc., all rights reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
-
- <2> 16/3/99 Quinn Added tests for InterfaceDisableLib.
- <1> 1/3/99 Quinn First checked in.
- */
-
- /////////////////////////////////////////////////////////////////
-
- // MoreIsBetter Setup
-
- #include "MoreSetup.h"
-
- // Standard Mac OS interfaces
-
- #include <MacTypes.h>
-
- // Standard C interfaces
-
- #include <stdio.h>
-
- // MIB Prototypes
-
- #include "MoreOSUtils.h"
-
- /////////////////////////////////////////////////////////////////
-
- static UInt16 gCodeSnippet[16];
-
- void main(void)
- {
- OSStatus err;
-
- printf("Hello Cruel World!\n");
- printf("TestMoreOSUtils\n");
- printf("-- A simple test program for the MoreOSUtils library.\n");
-
- printf("Testing Cache Flushing...\n");
-
- err = MakeDataPowerPCExecutable(gCodeSnippet, sizeof(gCodeSnippet));
- if (err == noErr) {
- // In the classic 68K case, this second call exercises a different
- // code path from the first.
- err = MakeDataPowerPCExecutable(gCodeSnippet, sizeof(gCodeSnippet));
- }
- if (err == noErr) {
- err = MakeData68KExecutable(gCodeSnippet, sizeof(gCodeSnippet));
- }
-
- #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
- TermMoreOSUtils();
- #endif
-
- printf("Testing Interrupt Disable/Enable...\n");
-
- {
- UInt16 initialMask;
- UInt16 maskIndex;
-
- // Save the initial interrupt mask for later restoration.
-
- initialMask = GetInterruptMask();
-
- // Set the interrupt mask to every legal value and make
- // sure it sticks.
-
- for (maskIndex = 0; maskIndex <= 7; maskIndex++) {
- (void) SetInterruptMask(maskIndex);
- if (GetInterruptMask() != maskIndex) {
- printf("••• Failed to set mask to %d.\n", maskIndex);
- }
- }
-
- // Check that the "set returns old value" behaviour.
-
- SetInterruptMask(7);
- if (SetInterruptMask(5) != 7) {
- printf("••• SetInterruptMask failed to return old values.\n");
- }
-
- // Restore the initial interrupt mask and make sure that works.
-
- SetInterruptMask(initialMask);
- if (GetInterruptMask() != initialMask) {
- printf("••• Failed to restore interrupt mask.\n");
- }
- }
-
- if (err == noErr) {
- printf("Success!\n");
- } else {
- printf("Failed with error %ld.\n", err);
- }
- }
-